//
//  TeleplayTableViewCell.m
//  PlayerFix
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 DAT. All rights reserved.
//

#import "TeleplayTableViewCell.h"
#import "TeleplayCollectionViewCell.h"
#import "DataMinModel.h"
@implementation TeleplayTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(65, 30);
    flowLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    flowLayout.minimumInteritemSpacing = 5;
    flowLayout.minimumLineSpacing = 5;
 
    self.myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(30, 0, 315, 200) collectionViewLayout:flowLayout];
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    self.myCollectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.myCollectionView];
    
    [self.myCollectionView registerClass:[TeleplayCollectionViewCell class] forCellWithReuseIdentifier:@"teleplayCollectionCell"];
    
}

- (void)setMovieArray:(NSArray *)movieArray
{
    if (_movieArray != movieArray) {
        _movieArray = movieArray;
    }
    
    CGFloat gao = movieArray.count / 4.0 * 35.0 +35.0;
    self.myCollectionView.frame = CGRectMake(30, 0, 315, gao);
//    NSLog(@"------%f", gao);

//    [self.myCollectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
//    NSLog(@"+++++++%ld",_movieArray.count);
    return _movieArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    TeleplayCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"teleplayCollectionCell" forIndexPath:indexPath];
    
    cell.dataMinModel = [_movieArray objectAtIndex:indexPath.row];
//  NSLog(@"===================%@",cell.dataMinModel);
//  NSLog(@"dataMinModel = %@",cell.dataMinModel);
    return cell;
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    DataMinModel *dataMinModel = [_movieArray objectAtIndex:indexPath.row];
    
    [self.Delegate getMessage:dataMinModel.m3u8 :_dataModel.title];
    
}

@end
